const { Types } = require('mongoose');
const DefaultDataAdapter = require('./../default-report/default-data-adapter');
const BlackBoxCovered = require('./../../../mongo/black-box-covered');
const ManualCovered = require('./../../../mongo/manual-covered');
const TestCase = require('./../../../mongo/test-case');
const TestCaseCoveredField = require('./../../../mongo/test-case-covered-field');

class DataAdapter extends DefaultDataAdapter {
  async getBlackBoxCovered(functionId) {
    return BlackBoxCovered.find({ functionId: Types.ObjectId(functionId) });
  }

  async getWhiteBoxCovered(functionId) {
    const filter = { functionId: Types.ObjectId(functionId) };
    const testcases = await TestCase.find(filter, ['_id']);
    filter.testcaseId = { $in: testcases.map((test) => test._id) };
    return TestCaseCoveredField.find(filter);
  }

  async getManualCovered(functionId) {
    return ManualCovered.find({ functionId: Types.ObjectId(functionId) });
  }
}

module.exports = DataAdapter;
